home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5410 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to tell if a file exists in C
  5. Date: Thu, 08 Feb 96 15:11:14 GMT
  6. Organization: none
  7. Message-ID: <823792274snz@genesis.demon.co.uk>
  8. References: <4eqkj6$ipo@charm.magnus.acs.ohio-state.edu> <m2buna4ugt.fsf@hawk.no>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <m2buna4ugt.fsf@hawk.no>
  15.            jan-henrik.haukeland@fou.telenor.no "jan-henrik haukeland" writes:
  16.  
  17. >Lawrence Kirby writes:
  18. >
  19. > : jan-henrik.haukeland@fou.telenor.no "jan-henrik haukeland" writes:
  20. > : 
  21. > : >Use the stat function, e.g.:
  22. > : >
  23. > : >int fexist(char * filename)
  24. >
  25. ><snip>
  26. >
  27. > : This function returns 3 distinct values. As such it does not return a
  28. > : voolean-like quantity. Therefore it is highly misleading to label two of
  29. > : those return values as TRUE and FALSE - you should find some more
  30. > : appropriate names.
  31. >
  32. >Should I ?
  33.  
  34. Definitely.
  35.  
  36. >Lets see, either the file exist or it don't - Yes.
  37.  
  38. No. In the general case there are 4 possibilities:
  39.  
  40. 1. The file is determined to exist.
  41. 2. The file is determined not to exist
  42. 3. it isn't possible to tell (e.g. inadequate permissions on a path element)
  43. 4. an error occurred
  44.  
  45. >Normal usage
  46. >of this function would be, something like:
  47. >
  48. >        if ( ! fexist(filename)) {
  49. >          /* Do stuff */
  50. >        }
  51. >
  52. >See, either it exist or it don't - and thats Boolean.
  53.  
  54. ! tests for zero or nonzero - it does *not* take a boolean operand although
  55. it generates a boolean-like result. x==5 also generates a boolean-like result
  56. but doesn't imply that x is boolean.
  57.  
  58. >But as a special
  59. >"fyzzy logic" service, it will distinguish between TRUE, because even if it
  60. >is TRUE that it exist, it's maybe not so true as You would like it to be,
  61. >because it's NOT_A_REGULAR_FILE (i.e. a dir. a /dev ..). It is then
  62. >possible to test for this. Beside did I say it was a boolean function, I
  63. >think not. 
  64.  
  65. You indicated that by using TRUE and FALSE as return values. They carry
  66. a strong implication that the quantity is boolean-like hence they are
  67. the only possible values. Since that is not the case here you are
  68. misleading the reader. It is simply better to use names that describe the
  69. meaning of the values more clearly.
  70.  
  71. -- 
  72. -----------------------------------------
  73. Lawrence Kirby | fred@genesis.demon.co.uk
  74. Wilts, England | 70734.126@compuserve.com
  75. -----------------------------------------
  76.